import {createRouter,createWebHashHistory} from 'vue-router';

const routes = [
	{path:'/',component:()=>import("./view/index.vue")},
	{
		path:'/login',
		component:()=>import("./view/login.vue"),
		meta:{
			title:'登录'
		}
	},
	{
		path:"/index",
		component:()=>import("./view/baceLayout.vue"),
		children:[
			{
				path:'/home',
				component:()=>import("./view/rjIndex.vue"),
				meta:{
					title:'首页'
				}
			},
			{
				path:'/workManage',
				component:()=>import("./view/workManage.vue"),
				meta:{
					title:'任务管理'
				}
			},
			{
				path:'/workList',
				component:()=>import("./view/workList.vue"),
				meta:{
					title:'任务列表'
				}
			},
			{
				path:'/work/:id',
				component:()=>import("./view/work.vue"),
				meta:{
					title:'任务'
				}
			},
			{
				path:'/profile',
				component:()=>import("./view/profile.vue"),
				meta:{
					title:'任务'
				}
			}
			,
			{
				path:'/publishWork',
				component:()=>import("./view/publishWork.vue"),
				meta:{
					title:'任务'
				}
			},
			{
				path:'/resource',
				component:()=>import("./view/resource.vue"),
				meta:{
					title:'任务'
				}
			},
			{
				path:'/member',
				component:()=>import("./view/memberManege.vue"),
				meta:{
					title:'任务'
				}
			}
			,
			{
				path:'/notice',
				component:()=>import("./view/publishNotice.vue"),
			}
			]
	}


];

const router = createRouter({
	history:createWebHashHistory('/'),
	routes
});
router.beforeEach((to,from,next)=>{
	if(to.path=='/login'){
		next()
	}
	else{
		let token = localStorage.getItem('account');
		if(token){
			next()
		}
		else{
			next('/login')
		}
	}
})
export default router;